//package org.kele.sc2020.consumer.mqlistener;
//
//import cn.hutool.core.util.RandomUtil;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.kele.sc2020.common.dto.Dog;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.messaging.handler.annotation.Header;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//
//@Component
//@Slf4j
//public class RabbitMsListenr {
//
//
////    @RabbitListener(queues = "kelequeue")
////    public void handleMess(String msg) {
////        log.info("收到消息:{}", msg);
////
////        // 如果消费一直失败 则会不断的重复消费, 从而击垮消费端服务, 需要开启 retry, 指定重试次数,  超出重试次数且消费失败的消息 被放入到 死信队列中后续人工处理;
////        throw new RuntimeException("haha dead");
////    }
//
//    @RabbitListener(queues = "kele-dlx-queue")
//    public void handleDeadMessage(String deadMessage) {
//        log.info("处理死信消息:{}", deadMessage);
//    }
//
//    @RabbitListener(queues = "kelequeue", ackMode = "MANUAL")
//    public void handleMess(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
//
//        try {
//            log.info("收到消息  手动确认:{} deliveryTag={}", msg, deliveryTag);
//            if ((RandomUtil.randomInt() & 1) == 0) {
//                throw new RuntimeException("偶数 异常");
//            }
//            log.info("消费成功");
//            channel.basicAck(deliveryTag, false); // 消费完成, 提交消息
//        } catch (Exception e) {
//            log.warn("拒绝消息 重新入列");
//            channel.basicReject(deliveryTag, true);// 消费失败时,拒绝消息, 重新入队;
//        }
//
//
//    }
//
//    @RabbitListener(queues = "dtoqueue")
//    public void handleDTOmessage(Dog dog, Message message) {
//        log.info("收到小狗:{}  deliveryTag={}", dog, message.getMessageProperties());
//    }
//
//}
